package com.bawei.module_main.ui

import android.view.View
import androidx.viewpager2.widget.ViewPager2
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.lib_common.Router
import com.bawei.lib_common.base.BaseActivity
import com.bawei.lib_common.base.BaseViewModel
import com.bawei.lib_storage.AppMMKV
import com.bawei.module_main.R
import com.bawei.module_main.adapter.GuidePageAdapter
import com.bawei.module_main.databinding.ActivityGuideBinding
import com.google.android.material.tabs.TabLayoutMediator

/**
 *author：yjk
 *description:
 *date：2025/6/10
*/
@Route(path = Router.GUIDE_PAGE)
class GuideActivity : BaseActivity<BaseViewModel,ActivityGuideBinding>() {
    override val mLayoutResId: Int
        get() = R.layout.activity_guide

    override fun initView() {
        super.initView()
        val isFirst=AppMMKV.needGuide
        if (!isFirst){
            jump()
        }
        mBinding.jump.setOnClickListener {
            AppMMKV.needGuide=false
            jump()
        }
    }
    private val pageLayouts = listOf(
        R.layout.guide,
        R.layout.guide,
        R.layout.guide
    )
    override fun initData() {
        super.initData()
        mBinding.vp.adapter = GuidePageAdapter(pageLayouts)
        TabLayoutMediator(mBinding.tabDots, mBinding.vp) { _, _ -> }.attach()
        mBinding.vp.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
            override fun onPageSelected(position: Int) {
                if (position == pageLayouts.size - 1) {
                    mBinding.btnEnter.visibility = View.VISIBLE
                    mBinding.btnEnter.setOnClickListener {
                        AppMMKV.needGuide=false
                        jump()
                        finish()
                    }
                }else{
                    mBinding.btnEnter.visibility = View.INVISIBLE
                }
            }
        })
    }
    fun jump(){
        ARouter.getInstance().build(Router.MAIN_PAGE).navigation()
    }




}